#!/usr/bin/python3.8.9
# -*- coding: utf-8 -*-

# @Author  : Tina Yu
# @Time    : 2021-12-30 19:31

# 手动输入添加用户页面
from appium.webdriver.common.mobileby import MobileBy

from homework.task_app.base.base_page import BasePage
from homework.task_app.page.add_member_list_page import AddMemberListPage


class AddMemberManualPage(BasePage):

    def save(self, name, phone_num):
        """保存"""
        # 输入成员信息
        self.input_member_info(name, phone_num)
        # 点击保存
        self.find_and_click(MobileBy.XPATH, "//*[@text='保存']")
        return AddMemberListPage(self.driver)

    def save_and_continual(self, name, phone_num):
        """保存并继续添加"""
        # 输入成员信息
        self.input_member_info(name, phone_num)
        # 点击保存
        self.find_and_click(MobileBy.XPATH, "//*[@text='保存并继续添加']")
        return AddMemberListPage(self.driver)

    def input_member_info(self, name, phone_num):
        # 添加姓名、手机号，也可以通过兄弟节点方式查找：following-sibling::
        self.find_and_send(MobileBy.XPATH,
                           "//*[contains(@text,'姓名')]/following-sibling::android.widget.EditText", name)
        self.find_and_send(MobileBy.XPATH,
                           "//*[contains(@text,'手机')]/..//*[@class='android.widget.EditText']", phone_num)

    def get_add_member_result(self):
        """手动输入添加成员的结果"""
        # 获取toast控件的文本
        toast_text = self.get_toast_text()
        return toast_text
